import 'package:flutter/material.dart';
import 'package:test1/View/MyRowText.dart';
import 'package:test1/View/TextWdigetPage.dart';

class Navigator_Page extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return Navigator_Page_State();
  }
}

class Navigator_Page_State extends State<Navigator_Page> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text("Navigator页面间跳转"),
        ),
        body: Column(
          children: <Widget>[
            //命名方式的路由 需要在main.dart中注册路由
            MyRowText("命名方式的路由", () =>
                Navigator.pushNamed(context, "listview_builder_page").then((
                    Object result) {
                  print("返回值：${result.toString()}");
                })
            ),
            MyRowText("构建方式的路由Navigator.push,then方式", () =>
                Navigator.push(context,
                    new MaterialPageRoute(builder: (BuildContext context) {
                      return TextWdigetPage(title: "传递的参数");
                    })
                ).then((Object result) {
                  print("返回值：${result.toString()}");
                })
//            Navigator.of(context).push(
//                new MaterialPageRoute(builder: (BuildContext context) {
//                  return TextWdigetPage(title: "传递的参数");
//                }))
            ),
            MyRowText("构建方式的路由Navigator.push，async和await方式", () async {
              var result = await Navigator.push(context,
                  new MaterialPageRoute(builder: (BuildContext context) {
                    return TextWdigetPage(title: "传递的参数");
                  })
              );
              print("返回值：${result.toString()}");
            }
            ),
            MyRowText("构建方式的路由Navigator.pushAndRemoveUntil", () =>
            //第一个为上下文环境，
            // 第二个参数为静态注册的对应的页面名称，
            // 第三个参数为跳转后的操作，route == null 为销毁当前页面
            Navigator.pushAndRemoveUntil(context,
                new MaterialPageRoute(builder: (BuildContext context) {
                  return TextWdigetPage(title: "传递的参数");
                }), (route) => route == null
            ).then((Object result) {
              print("返回值：${result.toString()}");
            })
//            Navigator.pushNamedAndRemoveUntil(
//                context, "listview_builder_page", (router) => router == null)
            ),
          ],
        ),
      ),

    );
  }

}